package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.net.FileReference;
	
	import sangpil.events.MoviePlayerEvent;
	import sangpil.media.MoviePlayer;

	public class TestFlvPlayer extends Sprite
	{
		private var player:MoviePlayer;
		public function TestFlvPlayer()
		{
			super();
			this.player = new MoviePlayer("./flvAsset/sampleMovie.flv");
			this.addChild(player);
			
			this.player.addEventListener(MoviePlayerEvent.VIDEO_STOP, onStop);
			this.player.addEventListener(MoviePlayerEvent.VIDEO_PLAYING, onPlay);
			this.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
			
		}
		
		private function onKeyDown(e:KeyboardEvent):void
		{
			trace(e.keyCode);
			switch(e.keyCode)
			{
				case 32://space
					this.player.changeUrl("./flvAsset/#6-1.flv");
				break;
				case 70://f
					var f:FileReference = new FileReference();
					f.addEventListener(Event.SELECT, onSelect);
					f.browse();
				break;
				case 80://p pause
					this.player.pause();
				break;
				case 82://r resume
					this.player.resume();
				break;
			}
		}
		
		private function onPlay(e:MoviePlayerEvent):void
		{
			trace(e.meta.current, e.meta.total);
		}
		
		private function onStop(e:MoviePlayerEvent):void
		{
			trace("stop received");
		}
		
		private function onSelect(e:Event):void
		{
			//trace("select", e.target);
			var f:FileReference = e.currentTarget as FileReference;
			trace(f.data, f.name);
			this.player.changeUrl("./flvAsset/"+f.name);
		}
		
	}
}